// by Xeno
#define THIS_FILE "x_playernamehud.sqf"
#include "x_setup.sqf"

if (isDedicated) exitwith {};

x_pm_received_ar = [];
x_pm_send_ar = [];
x_pm_add_ar = [];
x_player_name = name player;
x_pm_send_ar_update = false;

[2, "x_msg_net", {if (x_player_name == _this select 0) then {x_pm_add_ar set [count x_pm_add_ar, [_this select 1, _this select 2, date]];playSound "IncomingChallenge2";(format [(localize "STR_DOM_MISSIONSTRING_882"), _this select 1] + (_this select 2)) call FUNC(AddHudMsg)}}] call FUNC(NetAddEvent);

if (isNil "d_blockspacebarscanning") then {GVAR(blockspacebarscanning) = 1};
if (GVAR(BlockSpacebarScanning) == 0) then {
	FUNC(X_KeyboardHandlerKeyDown) = {((_this select 1) == 57)};
	waitUntil {sleep 0.412;!isNull (findDisplay 46)};
	(findDisplay 46) displayAddEventHandler ["KeyDown", {_this call FUNC(X_KeyboardHandlerKeyDown)}];
};

// 0 = over head, 1 = cursor target
x_show_pname_hud = (GVAR(playernames_state) > 0 && GVAR(show_playernames) == 0);

GVAR(show_player_namesx) = GVAR(playernames_state);

GVAR(dist_pname_hud) = 100;

sleep 10;

#ifndef __TT__
waitUntil {sleep 0.232;!isNil QGVAR(player_entities)};
GVAR(phud_units) = GVAR(player_entities);
//waitUntil {sleep 0.232;!isNil {GVAR(misc_store) getVariable (GVAR(player_entities) select ((count GVAR(player_entities)) - 1))}};
#else
waitUntil {sleep 0.232;!isNil QGVAR(entities_tt)};
GVAR(phud_units) = GVAR(entities_tt);
#endif
waitUntil {sleep 0.232;!isNil {GV(player,xr_pluncon)}};
waitUntil {sleep 0.232;!GVAR(still_in_intro)};

GVAR(phudraw3d) = -1;
GVAR(pnhudgroupcolor) = [0.7,0.7,0,0.6];
GVAR(pnhudothercolor) = [0.72,0.72,0.72,0.6];
GVAR(pnhuddeadcolor) = [0,0,0,0];
//GVAR(pnhudptext) = "<img image='%1' /> %2";
GVAR(pnhudptext) = "%2";
GVAR(phud_loc883) = localize "STR_DOM_MISSIONSTRING_883";
GVAR(phud_loc884) = localize "STR_DOM_MISSIONSTRING_884";
GVAR(phud_loc885) = localize "STR_DOM_MISSIONSTRING_885";
GVAR(phud_loc886) = localize "STR_DOM_MISSIONSTRING_886";

GVAR(pnhuddo2_prevCT) = objNull;
GVAR(showPlayerNameRSC_shown) = false;
GVAR(pnhuddo2_frskip) = 0;

if (x_show_pname_hud) then {
	GVAR(phudraw3d) = addMissionEventHandler ["Draw3D", {call FUNC(player_name_huddo)}];
} else {
	["player_hud2", {call FUNC(player_name_huddo2)},0] call FUNC(addPerFrame);
};